import { allGet } from '@/services/pc';
import { useEffect, useState } from 'react';
import { useLoginStatus } from './login';

export const useUserInfo = () => {
  const [userInfo, setUserInfo] = useState<{
    uid: any;
    username: any;
    isadmin: any;
    avatar: any;
    newprompt: any;
    newpm: any;
    isteacher: any;
    verify: any;
    needcontact: any;
  }>();

  const isLogin = useLoginStatus();

  useEffect(() => {
    (async (isLogin) => {
      if (isLogin) {
        const response = await allGet({ params: { mod: 'user', do: 'member', version: 'pc1.0' } });
        setUserInfo(response.data || {});
      }
    })(isLogin);
  }, [isLogin]);
  return { userInfo };
};
